package com.songhq.gateway;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

@EnableEurekaClient
@SpringBootApplication
public class AppGatewayApplication {

	private static final Logger logger = LoggerFactory.getLogger(AppGatewayApplication.class);
	
	//这个是以java代码的方式进行配置
	//@Bean
	public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
		
		return builder.routes().route(r ->r.path("/baidu").uri("https://baidu.com"))
				.route("websocket_route",r -> r.path("/apitopic1/**").uri("ws://127.0.0.1:6065"))
				.route(r -> r.path("/userapi/**").uri("lb://user/"))
				.build();
	}

	public static void main(String[] args) {
		SpringApplication.run(AppGatewayApplication.class, args);
		logger.info("start ApiGateWayApplication Done 程序启动成功");
	}

	
}
//如何理解这段代码 builder.routes().route(r ->r.path("/baidu").uri("https://baidu.com"))  函数式编程？？
//NettyWebServer
//BlockingNettyContext
//ServerWebExchangeUtils


//predicate  相关的类ServerWebExchange
//Filter   相关的GatewayFilter


